package cn.iocoder.yudao.module.member.controller.app.order.vo;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

@Schema(description = "用户 App - 用证书分记录 Response VO")
@Data
public class AppMemberCertifiOrderRecordRespVO {

    @Schema(description = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1024")
    private Long id;
    @Schema(description = "设备订单编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String certificateOrderCode;

    /**
     * 0:积分订单 1:设备订单
     */
    @Schema(description = "订单类型", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String certificateOrderType;
    /**
     * 0:公共池 1:独立池
     */
    @Schema(description = "购买类型0:公共池 1:独立池", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String poolType;

    private LocalDateTime createTime;

    /**
     *
     *版本类型编码
     */
    @Schema(description = "版本类型编码", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String versionTypeCode ;
    /**
     *
     *版本类型编码
     */
    @Schema(description = "版本类型名称", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String versionTypeName ;

    /**
     * 购买类型 秒出 0  ；预约 1
     */
    @Schema(description = "购买类型秒出 0  ；预约 1", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")

    private String classType ;

    /**
     *
     设备udid
     */
    @Schema(description = "设备udid", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")

    private String udid ;

    /**
     *
     是否掉签
     */
    @Schema(description = "是否掉签", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")

    private Boolean dropFlag =Boolean.FALSE ;


    /**
     * 描述文件地址
     */
    @Schema(description = "描述文件地址", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")

    private String profileUrl;

    /**
     * 证书链接
     */
    @Schema(description = "证书链接", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")

    private String certificateUrl;

    /**
     * 用户账号信息
     */
    @Schema(description = "用户账号信息", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String userAccount ;

    /**
     * p12地址
     */
    @Schema(description = "p12地址", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String p12Url;

    /**
     * p12密码
     */
    @Schema(description = "p12密码", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String p12Password;

    /**
     * 备注
     */
    @Schema(description = "备注", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String remark;

    /**
     * 设备来源 0:自己 1:苹果
     */
    private String sourceFlag;

    /**
     * 苹果设备id
     */
    @Schema(description = "苹果设备id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String deviceId;
    /**
     * 苹果证书id
     */
    @Schema(description = "苹果证书id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String cerId;
    /**
     * 苹果证书编码
     */
    @Schema(description = "苹果证书编码", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String cerNumber;
    /**
     * 苹果开发者账号id
     */
    @Schema(description = "苹果开发者账号id", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private Long appAccountId;
    /**
     * 账号类型（公共 个人）
     */
    @Schema(description = "账号类型（公共 个人）", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String accountType;
    /**
     * 质保类型（公共 个人）
     */
    @Schema(description = "质保类型（公共 个人）", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String warrantyType;

//    /**
//     * 版本 摆烂 躺平 加强
//     */
//    private String orderVersion;
    /**
     * 证书名称
     */
    @Schema(description = "证书名称", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String cerName;

    /**
     * 描述文件路径
     */
    @Schema(description = "描述文件路径", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "OD123")
    private String mpUrl;

    private Date cerExpireTime;
    /**
     * 设备类型
     */
    private String deviceModel;

    /**
     * 购买类型
     */
    private String buyType;

    /**
     * 售后时长
     */
    private Integer timeout;


    /**
     * 剩余质保时间
     */
    private Integer remainTime;

    private String cerStatus;

    public Integer getRemainTime() {
        if (ObjectUtil.isNull(timeout) || timeout == 0){
            return 0;
        }else {
            Date date = new Date();
            LocalDateTime localDateTime = this.getCreateTime();
            //获取系统默认时区
            ZoneId zoneId = ZoneId.systemDefault();
            //时区的日期和时间
            ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
            //获取时刻
            Date dateStart = Date.from(zonedDateTime.toInstant());
            long between = DateUtil.between( dateStart , date, DateUnit.DAY);
            return  timeout - (int)between;

        }
    }
}
